import wx
from Constant import *
from PublicMethod import *
from SelMaster_Selector import *
'''
Frame_SelMaster :

        The frame of selection player, user can take a look at before or next player through click
    
    left or right key on keyboard. Once user decide the selection, pushing Enter key to go to next 
    
    step. In each selection, frame will show the name and four aspects image of current player.
'''
class Frame_SelMaster(wx.Panel):
    '''
    Constructor : Frame_SelMaster
        parent : this object will add to it
        arg : list of argument that before setting
    '''
    def __init__(self, parent, arg):
        wx.Panel.__init__(self, parent, -1, size = (parent.GetSize()[0], parent.GetSize()[1] - 20))
        self.SetBackgroundColour("black")
        self._001_initialInstanceVariable(parent, arg)
        self._002_bindAction()
        self._003_createBackground()
        self._004_createTitleImg()
        self._005_createSelector()
        self.main.SetFocus()
    '''
    function _001 : initialize the variables used for this object
        main : the main frame
        arg : the before setting arguments
    '''
    def _001_initialInstanceVariable(self, main, arg):
        #pointer of main frame
        self.main = main
        #set argument
        self.arg = arg
        #image background
        self.imgBackground = None
        #image of title
        self.imgTitle = None
        #selector of player
        self.playerSelector = None
    '''
    function _002 : bind object event to specific method
    '''
    def _002_bindAction(self):
        self.main.Bind(wx.EVT_KEY_DOWN, self.SLOT001_OnKeyClick)
    '''
    function _003 : create background image of this frame
    '''
    def _003_createBackground(self):
        image = PublicMethod.ACT001_getBmpImage(FILE_NAME_BACKGROUND, self.GetSize()[0], self.GetSize()[1])
        self.imgBackground = wx.StaticBitmap(parent=self, bitmap=image)
        self.imgBackground.Show(False)
        self.imgBackground.Show(True)
    '''
    function _004 : create image of title
    '''
    def _004_createTitleImg(self):
        image = PublicMethod.ACT001_getBmpImage(DIR_IMG_SEL_PLAYER + "/img_selPlayer.png")
        position = ((self.main.GetSize()[0] - image.GetSize()[0]) / 2 - 25, 30)
        self.imgTitle = wx.BitmapButton(self, -1, image, pos = position, style = wx.FRAME_SHAPED)
        self.imgTitle.Enable(False)
    '''
    function _005 : create man selector
    '''
    def _005_createSelector(self):
        self.playerSelector = SelMaster_Selector(self)
    '''
    function _006 : destroy all object of this class
    '''
    def _006_destroyAll(self):
        self.imgBackground.Destroy()
        self.imgTitle.Destroy()
        self.playerSelector.ACT003_destroyAll()
        self.Destroy()
        del self
    '''
    function SLOT001 : slot of clicking on the keyboard
    '''
    def SLOT001_OnKeyClick(self, event):
        key = event.GetKeyCode()
        if key == wx.WXK_LEFT :  #click left key, show before player
            self.main.ACT001_playSound(SOUND_SELECT)  #play sound
            self.playerSelector.ACT002_showBefore()
        elif key == wx.WXK_RIGHT :  #click right key, show next player
            self.main.ACT001_playSound(SOUND_SELECT)  #play sound
            self.playerSelector.ACT001_showNext()
        elif key == 13 :  #click Enter key
            self.main.ACT001_playSound(SOUND_ENTER)  #play sound
            #set arguments
            main = self.main
            arg = self.arg
            selPlayerName = self.playerSelector.GET001_curSelectPlayerName()
            arg.append(selPlayerName)
            #destroy this object
            self._006_destroyAll()
            #create background image
            image = PublicMethod.ACT001_getBmpImage(FILE_NAME_BACKGROUND, main.GetSize()[0], main.GetSize()[1] - 20)
            imgBackground = wx.StaticBitmap(parent=main, bitmap=image)
            imgBackground.Show(False)
            imgBackground.Show(True)
            #open MainMap
            from MainMap import MainMap
            MainMap(main, arg, imgBackground)
        elif key == wx.WXK_ESCAPE :  #press key - Esc
            main = self.main
            self._006_destroyAll()
            from Frame_NewGame import Frame_NewGame
            Frame_NewGame(main)
'''
main program
'''
if __name__ == "__main__" :
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, size = (800, 600), pos = (50,50))
    Frame_SelMaster(frame, "", "", "")
    frame.Show()
    app.MainLoop()